package com.example.expresscabinet.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.expresscabinet.common.Result;
import com.example.expresscabinet.model.friend;
import com.example.expresscabinet.model.friendetail;
import com.example.expresscabinet.service.ICabinetService;
import com.example.expresscabinet.service.IFriendService;
import com.example.expresscabinet.service.IGetexpressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/friend")
public class friendController {

    @Autowired
    IFriendService friendService;

    @Autowired
    ICabinetService cabinetService;

    @Autowired
    IGetexpressService getexpressService;

    //添加请朋友代取的消息
    @GetMapping("/add/{receiver}/{sender}/{code}")
    public Result<?> add(@PathVariable String receiver,
                         @PathVariable String sender,
                         @PathVariable String code){
        Result res=friendService.addFriendMsg(receiver,sender,code);
        return Result.success(res);
    }

    //帮朋友取快递
    @GetMapping("/delete/{receiver}/{code}")
    public Result<?> delete(@PathVariable String receiver,
                         @PathVariable String code){
        friendService.deleteFriendMsg(receiver,code);
        int cost=getexpressService.takeGetexpress(code);
        cabinetService.takeEmptyCabinetByCode(code);
        return Result.success(cost);
    }

    //查询自己需要帮朋友取的快递
    @GetMapping("/queryNoTake/{receiver}")
    public Result<?> queryNoTake(@PathVariable String receiver,
                                 @RequestParam int pageNum,
                                 @RequestParam int pageSize){
        Page<friendetail> friendList=friendService.queryNoTake(receiver,pageNum,pageSize);
        return Result.success(friendList);
    }

    //查询自己帮朋友已取的快递
    @GetMapping("/queryTake/{receiver}")
    public Result<?> queryTake(@PathVariable String receiver,
                               @RequestParam int pageNum,
                               @RequestParam int pageSize){
        Page<friendetail> friendList=friendService.queryTake(receiver,pageNum,pageSize);
        return Result.success(friendList);
    }

}
